package com.ypf.delaycancelorder.service.impl;

import com.ypf.delaycancelorder.entity.Order;
import com.ypf.delaycancelorder.mapper.OrderMapper;
import com.ypf.delaycancelorder.service.IOrderService;
import com.ypf.delaycancelorder.service.ex.InsertException;
import com.ypf.delaycancelorder.service.ex.UpdateException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class OrderService implements IOrderService {
    @Autowired
    private OrderMapper orderMapper;

    @Override
    public void insert(Order order) {
        Integer insert= orderMapper.insertOrder(order);
        if (insert<1){
           throw new InsertException();
        }
    }

    @Override
    public void updateByOrderNo(String orderNo, Integer status) {
        Integer update=orderMapper.updateByOrderNo(orderNo,status,new Date());
        if (update<1){
            throw new UpdateException();
        }
    }

    @Override
    public Order findByOrderNo(String orderNo) {
        return orderMapper.findByOrderNo(orderNo);
    }
}
